import requests
from bs4 import BeautifulSoup

keyword = "loser"

url=f'https://search.bilibili.com/all?vt=90152113&keyword={keyword}&from_source=webtop_search&spm_id_from=333.1007'

response = requests.get(url)

#with open('1.html','w',encoding='utf8') as f:
#    f.write(response.text)

bs = BeautifulSoup(response.text,"html.parser")

videos = bs.select(".video-item.matrix")

for video in videos:

    work = {}

    work['title'] = video.select(".title")[0].text
    work['watch_num'] = video.select(".watch-num")[0].text.replace('\n','').replace(' ','')
    work['time'] = video.select(".time")[0].text.replace('\n','').replace(' ','')
    work['up_name'] = video.select(".up-name")[0].text.replace('\n','').replace(' ','')

    print(work)
    break
